$(function(){
	$('.mc').css('display','none');
	$('#categorys').hover(function(){
		$(this).children('.mc').toggle();
	});
//	getRecommendList();
	getPlateProductList();
	getBrowsedMcList();
});

function getBrowsedMcList() {
	var mcRs = $.cookie('browsedMc');
	if (mcRs) {
		var res = JSON.parse(mcRs);
		var newRes = res.reverse();
		var divStr = '';
		$.each(newRes,function(i,n){
			divStr += [
				'<li>',
				'<a href="file.html?id=',n.id,'">','<img src="',n.imgUrl,'" width="160" height="160"/>','</a>',
				'<p>','<a href="file.html?id=',n.id,'">',n.name,'</a>','<p class="cDGray">金麒价：<strong>￥',n.price,'</strong>','</p>',
				'</li>'
			].join('');
		});
		$('#browseMcList').append(divStr);
	}
}
function getRecommendList() {
	var url = '/json?action=QUERY_T_PLATE_PRODUCT_ACTION';
	$UI.listPage(url,'T_PLATE_PRODUCT','#buyedList',printRecommendRes,'');
}

function printRecommendRes(obj,result,i,n,total) {
	if (result && obj.PLATE_CODE == '1014' && obj.PRODUCT_LIST.length>0) {
		$.each(obj.PRODUCT_LIST,function(j,m){
			if (j+1>4) return false;
			var appendStr = [
				'<li>',
				'<div>',
				'<p>','<a href="file.html?id=',m.productId,'">',m.productName,'</a>','</p>',
				'<p class="fb">￥',m.memberPrice,'</p>',
				'</div>',
				'<a href="file.html?id=',m.productId,'">','<img src="../upload/product/'+m.productNo+'.jpg" width="160" height="160"/>','</a>',
				'</li>'
			].join('');
			$(result).append(appendStr);
		});
	}
}

function getPlateProductList() {
	var url = '/json?action=QUERY_T_PLATE_PRODUCT_ACTION';
	$UI.listPage(url,'T_PLATE_PRODUCT','#newList',printPlateProductRes,'');
}

function printPlateProductRes(obj,result,i,n,total) {
	var panel = '';
	switch(obj.PLATE_CODE) {
		// 新品上市
		case '1012':
			panel = '#newList';
			break;
		// 热销商品
		case '1013':
			panel = '#hotItemList';
			break;
		default:
			break;
	}
	if (panel && obj.PRODUCT_LIST.length>0) {
		$.each(obj.PRODUCT_LIST,function(j,m){
			if ($(panel+'>li').length>2) return true;
			var appendStr = [
				'<li>',
				'<a href="file.html?id=',m.productId,'">','<img src="../upload/product/'+m.productNo+'.jpg" width="160" height="160"/>','</a>',
				'<p>','<a href="file.html?id=',m.productId,'">',m.productName,'</a>','</p>',
				'<p class="cDGray">金麒价：','<strong>￥',m.memberPrice,'</strong>','</p>',
				'</li>'
			].join('');
			$(panel).append(appendStr);
		});
	}
}